package com.hboxs.asl.controller.app.member;

import com.hboxs.asl.JsonMessage;
import com.hboxs.asl.controller.app.BaseController;
import com.hboxs.asl.entity.Feedback;
import com.hboxs.asl.entity.Member;
import com.hboxs.asl.service.FeedbackService;
import com.hboxs.asl.service.MemberService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by xxx on 2016/12/06
 */
@Controller(value = "appMemberFeedbackController")
@RequestMapping(value = "/app/m/feedback")
public class FeedbackControl extends BaseController {

    @Resource(name = "memberServiceImpl")
    private MemberService memberService;
    @Resource(name = "feedbackServiceImpl")
    private FeedbackService feedbackService;

    /**
     * 提交反馈
     */
    @RequestMapping(value = "/submit", method = RequestMethod.POST)
    public
    @ResponseBody
    Object submit(Feedback feedback) {

        try {
            Member member = memberService.getCurrentByToken();
            if (member == null) {
                return JsonMessage.USER_NOT_LOGIN;
            }
            feedback.setMember(member);
            feedbackService.save(feedback);
            return JsonMessage.success();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonMessage.UNKNOWN_ERROR;
    }

}
